

import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;

public class Buffer_consola {

	private static Queue<String> cola;
	private static FileWriter fw;
	
	public Buffer_consola(String salida) throws IOException 
	{
		cola=new LinkedList<String>();
		fw=new FileWriter(salida);
	}
	
	private static void cerrar_buffer() throws IOException
	{
		fw.close();
	}

	public boolean isEmpty()
	{
		return cola.isEmpty();
	}
	
	public void write_to_file()
	{
		StringBuffer sb=new StringBuffer();
		String cad;
		
		while(!cola.isEmpty())
		{
			cad=cola.poll();
			sb.append(cad);
		}
		
		try {
			fw.write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public synchronized void put(String obj) 
	{		
		try
		{
			cola.add(obj);
			
			if(cola.size()>100)
				write_to_file();
			
		}
		catch(IllegalStateException e)
		{
			//crawler.suspend();	
			e.printStackTrace();
			//base_datos.resume();
		}
	}
	
}
